import { navigationTop, navigationBottom } from "./data.js"
import { ApihotArticle } from "../../api/index"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navigationTop,
    navigationBottom,
    articleList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getHotArticle()
  },

  onShow() {
    app.ws.setBadge()
  },

  getHotArticle() {
    ApihotArticle().then(res => {
      this.setData({
        articleList: res.data.map(item => {
          item.content = item.content.replace(/(<\/?.+?\/?>)|&nbsp;|\s/g, '').slice(0,100)
          item.pic = app.setPath(item.pic)
          item.created_at = item.created_at.replace(/^(\d{4})-(\d{2})-(\d{2}).*/,"$1年$2月$3日")
          return item
        })
      })
    })
  },

  onClickTop(e) {
    const type = e.currentTarget.dataset.type
    switch (type) {
      case 1: {    
        wx.navigateTo({
          url: '/pages/user/inventory/index?activeTab=a',
        })    
        break;
      }
        
      case 2: {
        wx.navigateTo({
          url: '/pages/user/inventory/index?activeTab=b',
        })    
        break;
      }
        
      case 3: {
        wx.reLaunch({
          url: '/pages/visit/service/index',
        })
        break;
      }
        
      case 4: {
        wx.navigateTo({
          url: '/pages/user/priceInquiry/index',
        })
        break;
      }
      default: {
        console.log("other")
        break;
      }
    }
  },
  
  onClickBottom(e) {
    const type = e.currentTarget.dataset.type
    switch (type) {
      case 1: {
        wx.setStorageSync('PAGEATOB', "b")
        wx.reLaunch({
          url: '/pages/visit/service/index',
        })
        break;
      }
        
      case 2: {
        wx.navigateTo({
          url: '/pages/visit/bedRoom/index',
        })
        break;
      }
        
      case 3: {
        wx.navigateTo({
          url: '/pages/visit/outpatient/index',
        })
        break;
      }
        
      case 4: {
        wx.navigateTo({
          url: '/pages/user/report/index',
        })
        break;
      }
      default: {
        console.log("other")
        break;
      }
    }
  },

  onClickLookMore() {
    wx.switchTab({
      url: '/pages/science/article/index',
    })
  },

  onGoVisitorEdit() {
    wx.navigateTo({
      url: '/pages/user/visitorEdit/index',
    })
  },

  onHide() {

  },

  onUnload() {

  },

  onShareAppMessage() {

  }
})